<?php

namespace app\common\model;

class WeixinIntegralReceive extends Base
{

    protected $deleteTime = "delete_time";

    /**
     * 获取用户消费积分总数
     * @param string $openid
     * @return int|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getUserReceiveByCount(string $openid = '')
    {
        $integral = $this->field('sum(integral) as integral')
            ->where('openid', $openid)
            ->find();
        return $integral['integral'] ?? 0;
    }
}